package com.warm.pump.module.sys.service.impl;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.module.sys.bean.po.gen.DictItem;
import com.warm.pump.module.sys.dao.gen.DictItemDao;
import com.warm.pump.module.sys.service.IDictItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("DictItemService")
@CacheConfig(cacheNames = "DictItem")
public class DictItemServiceImpl implements IDictItemService {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private DictItemDao dictItemDao;


    @Override
    public DictItem queryObject(Long id) {
        return dictItemDao.selectByPrimaryKey(id);
    }

    @Cacheable(key = "targetClass + methodName +#p0")
    public DictItem queryObject(Map<String, Object> map) {
        return dictItemDao.selectByMap(map);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<DictItem> queryList(Map<String, Object> map) {
        return dictItemDao.getListByMap(map);
    }

    @Override
    public PageBean getPageBeanByMap(Map map, int pageNo, int pageSize) {
        logger.debug("日志查询");
        return dictItemDao.getPageBeanByMap(map, pageNo, pageSize);
    }


    @Override
    public int queryTotal(Map<String, Object> map) {
        return dictItemDao.countTotalByMap(map);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void save(DictItem dictItem) {
        dictItemDao.insertSelective(dictItem);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void update(DictItem dictItem) {
        dictItemDao.updateByPrimaryKeySelective(dictItem);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void delete(Long id) {
        dictItemDao.deleteByPrimaryKey(id);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void delete(Map<String, Object> map) {
        dictItemDao.deleteByMap(map);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void deleteBatch(Long[] ids) {
        Map<String, Object> map = new HashMap<>();
        map.put("id_in", ids);
        dictItemDao.deleteByMap(map);
    }

}
